package com.hm.hsw2;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;

public class Demo {
    public static void main(String[] args) throws DocumentException {
        SAXReader sr = new SAXReader();
        Document document = sr.read(new File("mybooks.xml"));
        Element ret = document.getRootElement();
        List<Element> elements = ret.elements();
        elements.forEach(o->{
            Attribute id = o.attribute("id");
            String id0 = id.getValue();
            Element name = o.element("name");
            String name0 = name.getText();
            Element press = o.element("press");
            String press0 = press.getText();
            Element publicationDate = o.element("publicationDate");
            String publicationDateText0 = publicationDate.getText();
            Element price = o.element("price");
            String price0 = price.getText();
            System.out.println("id="+id0+"  name="+name0+" press="+press0+" publicationDate="+publicationDateText0+" price="+price0);
        });
    }
}
